package com.youku.plugins.toolboxV4.model
{
   import com.youku.interfaces.IPlayerProxy;
   import com.youku.PlayerConfig;
   
   public class ToolboxDataProxy extends Object
   {
      
      public function ToolboxDataProxy(param1:IPlayerProxy) {
         super();
         this._toolboxData = new ToolboxData();
         this._playerProxy = param1;
      }
      
      public static var DEFAULT_QUALITY:String = "low";
      
      public static var DEFAULT_CONTINUOUS:Boolean = true;
      
      public static var DEFAULT_JUMP:Boolean = true;
      
      public static var DEFAULT_VOICE:String = "default";
      
      private var _toolboxData:ToolboxData;
      
      private var _playerProxy:IPlayerProxy;
      
      public function get toolboxData() : ToolboxData {
         return this._toolboxData;
      }
      
      public function reset() : void {
         this._toolboxData = new ToolboxData();
      }
      
      public function saveData(param1:ToolboxData) : Boolean {
         var _loc2_:* = false;
         if(!(this.toolboxData.defaultQuality == param1.defaultQuality) || !(this.toolboxData.isContinuous == param1.isContinuous) || !(this.toolboxData.isJump == param1.isJump) || !(this.toolboxData.quality == param1.quality) || !(this.toolboxData.voice == param1.voice))
         {
            _loc2_ = true;
         }
         if(this._toolboxData.defaultQuality != param1.defaultQuality)
         {
            this._playerProxy.fsoProxy.setDefaultQuality(param1.defaultQuality);
         }
         if(this.toolboxData.voice != param1.voice)
         {
            this._toolboxData.isVoiceUserChanged = true;
         }
         else
         {
            this._toolboxData.isVoiceUserChanged = false;
         }
         if(this.toolboxData.quality != param1.quality)
         {
            this._toolboxData.quality = param1.quality;
            PlayerConfig.tempQuality = param1.quality;
            this._toolboxData.isQualityUserChanged = true;
         }
         else if(this.toolboxData.defaultQuality != param1.defaultQuality)
         {
            this._toolboxData.quality = this.defaultQualityToQuality(param1.defaultQuality);
            PlayerConfig.tempQuality = this._toolboxData.quality;
            if(this._toolboxData.quality == param1.quality)
            {
               this._toolboxData.isQualityUserChanged = false;
            }
            else
            {
               this._toolboxData.isQualityUserChanged = true;
            }
         }
         else
         {
            this._toolboxData.quality = param1.quality;
            this._toolboxData.isQualityUserChanged = false;
         }
         
         this._toolboxData.defaultQuality = param1.defaultQuality;
         this._toolboxData.isContinuous = param1.isContinuous;
         this._toolboxData.isJump = param1.isJump;
         this._toolboxData.voice = param1.voice;
         this._playerProxy.fsoProxy.setContinuous(param1.isContinuous);
         this._playerProxy.fsoProxy.setJump(param1.isJump);
         this._playerProxy.fsoProxy.setDefaultVoice(param1.voice);
         return _loc2_;
      }
      
      public function saveQualityData(param1:ToolboxData) : Boolean {
         var _loc2_:* = false;
         if(!(this.toolboxData.quality == param1.quality) || !(this.toolboxData.defaultQuality == param1.defaultQuality))
         {
            _loc2_ = true;
         }
         if(this._toolboxData.defaultQuality != param1.defaultQuality)
         {
         }
         if(this.toolboxData.quality != param1.quality)
         {
            this._toolboxData.quality = param1.quality;
            this._toolboxData.isQualityUserChanged = true;
         }
         else if(this.toolboxData.defaultQuality != param1.defaultQuality)
         {
            this._toolboxData.quality = this.defaultQualityToQuality(param1.defaultQuality);
            if(this._toolboxData.quality == param1.quality)
            {
               this._toolboxData.isQualityUserChanged = false;
            }
            else
            {
               this._toolboxData.isQualityUserChanged = true;
            }
         }
         else
         {
            this._toolboxData.quality = param1.quality;
            this._toolboxData.isQualityUserChanged = false;
         }
         
         this._toolboxData.defaultQuality = param1.defaultQuality;
         return _loc2_;
      }
      
      public function saveFunctionalData(param1:ToolboxData) : Boolean {
         var _loc2_:* = false;
         if(!(this.toolboxData.isContinuous == param1.isContinuous) || !(this.toolboxData.isJump == param1.isJump))
         {
            _loc2_ = true;
         }
         this._toolboxData.isContinuous = param1.isContinuous;
         this._toolboxData.isJump = param1.isJump;
         return _loc2_;
      }
      
      public function saveDVDData(param1:ToolboxData) : Boolean {
         var _loc2_:* = false;
         if(this.toolboxData.voice != param1.voice)
         {
            this._toolboxData.isVoiceUserChanged = true;
            _loc2_ = true;
         }
         else
         {
            this._toolboxData.isVoiceUserChanged = false;
         }
         this._toolboxData.voice = param1.voice;
         return _loc2_;
      }
      
      private function defaultQualityToQuality(param1:String) : String {
         var _loc2_:* = "";
         switch(param1)
         {
            case "low":
               _loc2_ = "flv";
               break;
            case "mid":
               _loc2_ = "mp4";
               break;
            case "high":
               _loc2_ = "hd2";
               break;
            case "1080P":
               _loc2_ = "hd3";
               break;
            case "auto":
               _loc2_ = "auto";
               break;
         }
         return _loc2_;
      }
   }
}
